package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import com.itheima.pojo.PageResult;
import com.itheima.service.EmpService;
import org.springframework.stereotype.Service;

@Service
public class EmpServiceImpl extends ServiceImpl<EmpMapper, Emp> implements EmpService {

    @Override
    public PageResult<Emp> getPageResult(EmpQueryParam param) {
        //1.封装Page分页对象
        Page<Emp> empPage = Page.of(param.getPage(), param.getPageSize());
        //2.设置排序条件
        empPage.addOrder(OrderItem.desc("update_time"));
        //3.调用page方法做分页查询
        empPage = page(empPage);
        //4.封装PageResult结果返回
        return new PageResult<>(empPage.getTotal(), empPage.getRecords());
    }
}
